﻿@page "/xlsio/embedded-chart"
@inject Microsoft.JSInterop.IJSRuntime JS
@inject Microsoft.AspNetCore.Hosting.IWebHostEnvironment hostingEnvironment
@using System.IO;

@using Syncfusion.Blazor.Buttons
@*Hidden:Lines*@

@using BlazorDemos.Data.FileFormats.XlsIO

@*End:Hidden*@
@inherits SampleBaseComponent;

<SampleDescription>
    <p>This sample demonstrates how to create a simple chart using XlsIO.</p>
</SampleDescription>
<ActionDescription>
   <p>Essential XlsIO has APIs for creating an embedded chart. The <b>IChartShape</b> interface represents the embedded chart in memory. This object can be used to format and modify chart settings, which is similar to modifying chart properties using Excel.</p>
<p style='display: block'><b>Features:</b></p>
<ul>
<li>Creation of embedded chart types</li>
<li>Creation of chart from values in a template document</li>
</ul>
</ActionDescription>

<div class="control-section">
    <p style="font-weight:normal">Click the button to view an Excel spreadsheet generated by Essential XlsIO. Please note that Microsoft Excel Viewer or Microsoft Excel is required to view the resultant document.</p>

    <div class="radio-control">
        <h5 class="row">Save As:</h5>
        <div class="e-radio-wrapper">
            <SfRadioButton Label="XLS" Name="XLS" Value=@("XLS") @bind-Checked="@excelVersion"></SfRadioButton>
        </div>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <div class="e-radio-wrapper">
            <SfRadioButton Label="XLSX" Name="XLSX" Value=@("XLSX") @bind-Checked="@excelVersion"></SfRadioButton>
        </div>
    </div>
    <div class="button-section">
        <div id="button-control">
            <div class="row">
                <div>
                    <SfButton @onclick="EmbeddedChartXlsIO">Create Document</SfButton>
                </div>
            </div>
        </div>
    </div>
</div>

<style>
    .radio-control {
        margin: 5% 0 2% 0;
    }

    .control-section .row {
        margin: 10px 0;
    }
</style>

@code {
    MemoryStream excelStream;
    string excelVersion = "XLSX";

    /// <summary>
    /// Create and download the Excel document with embedded chart
    /// </summary>
    public async Task EmbeddedChartXlsIO()
    {
        EmbeddedChartService service = new EmbeddedChartService(hostingEnvironment);
        excelStream = service.EmbeddedChartXlsIO(excelVersion);
        if (excelVersion == "XLSX")
        {
            await JS.SaveAs("Sample.xlsx", excelStream.ToArray());
        }
        else
        {
            await JS.SaveAs("Sample.xls", excelStream.ToArray());
        }
    }
}